import { io } from 'socket.io-client'
import VerifyFormDialog from '../components/VerifyFormDialog'
import Vue from 'vue'

const VConstructor = Vue.extend(VerifyFormDialog)

const socket = io('http://localhost:3200')

socket.on('showVerifyText', data => {
  console.log('showVerifyText')
  console.log(data)
  showVerifyImg(data)
})

const showVerifyImg = (base64) => {
  const imgSrc = 'data:image/jpg;base64,' + base64
  // eslint-disable-next-line no-new
  const item = new VConstructor({
    propsData: {
      imgSrc: imgSrc,
      onClickCB: (result) => {
        console.log(result)
        socket.emit('verifyResult', result)
      },
      onClickCancel: () => {
        socket.emit('verifyCancel')
      }
    },
    data () {
      return {
        dialogFormVisible: true
      }
    }
  })

  item.$mount()
  document.body.appendChild(item.$el)
}
